import os,shutil
from PIL import Image

def get_aspect_ratio(image_path):
    with Image.open(image_path) as img:
        width, height = img.size
        if width / height >0.8 or width<1200:
            return False
        else:
            return True            



dir="Z:/系统/0-平铺细节图/"
dir2="D:/Desk/系统图库/平铺集/"
tag={'success':0,'fail':0,'wh-wrong':0,'ever':0,'type':0}
files=os.listdir(dir)
for file in files:
    if os.path.isdir(dir+file) and file != '格式不符合映射':
        if not os.path.exists(dir2+file):
            os.makedirs(dir2+file)
        files2=os.listdir(dir+file)
        for file2 in files2:
            if file2.lower().endswith(('.jpg','.png')):
                if not os.path.exists(dir2+file+'/'+file2):
                    if get_aspect_ratio(dir+file+'/'+file2):
                        try:
                            shutil.copy(dir+file+'/'+file2,dir2+file+'/'+file2)
                            tag['success']+=1
                        except:
                            tag['fail']+=1
                    else:
                        if not os.path.exists(dir+'格式不符合映射/'+file):
                            os.makedirs(dir+'格式不符合映射/'+file)
                        shutil.move(dir+file+'/'+file2,dir+'格式不符合映射/'+file+'/'+file2)
                        tag['wh-wrong']+=1
                else:
                    tag['ever']+=1
            else:
                if not os.path.exists(dir+'格式不符合映射/'+file):
                    os.makedirs(dir+'格式不符合映射/'+file)
                shutil.move(dir+file+'/'+file2,dir+'格式不符合映射/'+file+'/'+file2)
                tag['type']+=1
print(tag)
